<?php

declare(strict_types=1);

namespace App\Job\Notification;

use App\Utils\LoggerUtil;
use Hyperf\AsyncQueue\Job;
use Throwable;

class UMengMsgPushJob extends Job
{
    private mixed $params;

    public function __construct($params)
    {
        // 这里最好是普通数据，不要使用携带 IO 的对象，比如 PDO 对象
        $this->params = $params;
    }

    public function handle()
    {
        $this->job($this->params);
    }

    private function job(mixed $origin)
    {
        try {
            $body = json_decode($origin, true);
            $uid = $body['uid'];
            $message = $body['message'];
            $package = $body['package'] ?? '';
            $from_uid = $body['from_uid'] ?? 0;
            LoggerUtil::write("umeng_msg_push_queue", $body);
        } catch (Throwable $e) {
            LoggerUtil::write('umeng_msg_push_queue', [
                $e->getFile(), $e->getLine(), $e->getMessage()
            ]);
        }
    }
}
